//index.js
const app = getApp()
Page({
  data: {
    navData: [{
        text: '星期一'
      },
      {
        text: '星期二'
      },
      {
        text: '星期三'
      },
      {
        text: '星期四'
      },
      {
        text: '星期五'
      },
      {
        text: '星期六'
      },
      {
        text: '星期日'
      }
    ],
    currentTab: 0,
    navScrollLeft: 0,
  },
  //事件处理函数
  onLoad: function () {
    wx.getSystemInfo({
      success: (res) => {
        this.setData({
          windowHeight: res.windowHeight,
          windowWidth: res.windowWidth
        })
      },
    })
  },
  switchNav(event) {
    var cur = event.currentTarget.dataset.current;
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 5;
    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },
  switchTab(event) {
    var cur = event.detail.current;
    var singleNavWidth = this.data.windowWidth / 5;
    this.setData({
      currentTab: cur,
      navScrollLeft: (cur - 2) * singleNavWidth
    });
  }
})